package mylib.dir;

/**
 * Created with IntelliJ IDEA.
 * User: 1
 * Date: 20.07.12
 * Time: 16:21
 * To change this template use File | Settings | File Templates.
 */
public class Fenwick32 {
    int[] data;

    public Fenwick32(int n) {
        data = new int[n + 1];
    }

    public long get(int r) {
        long res = 0;
        for (++r; r >= 1; r -= r & -r)
            res += data[r];
        return res;
    }

    public long get(int l, int r) {
        return get(r) - get(l - 1);
    }

    public void add(int r, int by) {
        for (++r; r < data.length; r += r & -r)
            data[r] += by;
    }
}
